import Vue from "vue";
import App from "./App";
import * as filters from "./utils/filters.js"; // global filter
import uView from "uview-ui";
import store from "./store";
import WebIM from './utils/WebIM';




Object.keys(filters).forEach((key) => {
    Vue.filter(key, filters[key]);
});

const msg = (title, duration = 1500, mask = false, icon = "none") => {
    //统一提示方便全局修改
    if (Boolean(title) === false) {
        return;
    }
    uni.showToast({
        title,
        duration,
        mask,
        icon,
    });
};
// 引入vuex
Vue.prototype.$store = store;
Vue.use(uView);
Vue.config.productionTip = false;
// 主题色
Vue.prototype.$mainColor = "#ff3c2a";
// 高亮主题色
Vue.prototype.$lightColor = "#ff6b35";
// 可直接 this.$api调用
Vue.prototype.$api = { msg };
Vue.mixin({
    methods: {
        setData: function(obj, callback) {
            let that = this;
            let keys = [];
            let val, data;
            Object.keys(obj).forEach(function(key) {
                keys = key.split('.');
                val = obj[key];
                data = that.$data;
                keys.forEach(function(key2, index) {
                    if (index + 1 == keys.length) {
                        that.$set(data, key2, val);
                    } else {
                        if (!data[key2]) {
                            that.$set(data, key2, {});
                        }
                    }
                    data = data[key2];
                })
            });
            callback && callback();
        }
    }
});

App.mpType = "app";

const app = new Vue({
    ...App,
    WebIM,
    store
});
app.$mount();